import Vue from 'vue'
import VueRouter from 'vue-router'
import utils from '../utils/utils'
import Toast from 'vant'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: 'login' */ '../views/login/login'),
  },
  {
    path: '/home',
    name: 'home',
    component: () => import(/* webpackChunkName: 'home' */ '../views/home/home'),
    meta: {
      isTabbar: true,
      index: 0,
      keepAlive: true,
    },
  },
  {
    path: '/class',
    name: 'class',
    component: () =>
      import(/* webpackChunkName: 'class' */ '../views/classification/classification'),
    meta: {
      isTabbar: true,
      index: 1,
    },
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import(/* webpackChunkName: 'cart' */ '../views/cart/cart'),
    meta: {
      isTabbar: true,
      index: 2,
    },
  },
  {
    path: '/user',
    name: 'user',
    component: () => import(/* webpackChunkName: 'user' */ '../views/user/user'),
    meta: {
      isTabbar: true,
      index: 3,
    },
  },
  {
    path: '/resetPwd',
    name: 'resetPwd',
    component: () =>
      import(/* webpackChunkName: 'resetPwd' */ '../views/login/resetPwd'),
  },
  {
    path: '/register',
    name: 'register',
    component: () =>
      import(/* webpackChunkName: 'register' */ '../views/login/register'),
  },
  {
    path: '/search',
    name: 'search',
    component: () => import(/* webpackChunkName: 'search' */ '../views/home/search'),
  },
  {
    path: '/seckill',
    name: 'seckill',
    component: () => import(/* webpackChunkName: 'seckill' */ '../views/home/seckill'),
  },
  {
    path: '/bonus',
    name: 'bonus',
    component: () => import(/* webpackChunkName: 'bonus' */ '../views/home/bonus'),
  },
  {
    path: '/goodsDetail',
    name: 'goodsDetailDetail',
    component: () =>
      import(/* webpackChunkName: 'goodsDetail' */ '../views/goods/goodsDetail'),
  },
  {
    path: '/goodsComments',
    name: 'goodsComments',
    component: () =>
      import(/* webpackChunkName: 'goodsComments' */ '../views/goods/goodsComments'),
  },
  {
    path: '/shopHome',
    name: 'shopHome',
    component: () =>
      import(/* webpackChunkName: 'shopHome' */ '../views/goods/shopHome'),
    children: [
      {
        path: 'shopChoice',
        name: 'shopChoice',
        component: () =>
          import(/* webpackChunkName: 'shopChoice' */ '../views/goods/shopHomeChoice'),
      },
      {
        path: 'shopGoods',
        name: 'shopGoods',
        component: () =>
          import(/* webpackChunkName: 'shopChoice' */ '../views/goods/shopHomeGoods'),
      },
    ],
  },
  {
    path: '/orderConfirm',
    name: 'orderConfirm',
    component: () =>
      import(/* webpackChunkName: 'orderConfirm' */ '../views/order/orderConfirm'),
  },
  {
    path: '/orderSuccess',
    name: 'orderSuccess',
    component: () =>
      import(/* webpackChunkName: 'orderSuccess' */ '../views/order/orderSuccess'),
  },
  {
    path: '/addressList',
    name: 'addressList',
    component: () =>
      import(/* webpackChunkName: 'addressList' */ '../views/order/addressList'),
  },
  {
    path: '/addressEdit',
    name: 'addressEdit',
    component: () =>
      import(/* webpackChunkName: 'addressEdit' */ '../views/order/addressEdit'),
  },
  {
    path: '/myOrder/:type?',
    name: 'myOrder',
    component: () => import(/* webpackChunkName: 'myOrder' */ '../views/order/myOrder'),
  },
  {
    path: '/orderDetail/:id?',
    name: 'orderDetail',
    component: () =>
      import(/* webpackChunkName: 'orderDetail' */ '../views/order/orderDetail'),
  },
  {
    path: '/orderAfterSale',
    name: 'orderAfterSale',
    component: () =>
      import(/* webpackChunkName: 'orderAfterSale' */ '../views/order/orderAfterSale'),
  },
  {
    path: '/orderEvaluation',
    name: 'orderEvaluation',
    component: () =>
      import(
        /* webpackChunkName: 'orderEvaluation' */ '../views/order/orderEvaluation'
      ),
  },
  {
    path: '/orderRefund',
    name: 'orderRefund',
    component: () =>
      import(/* webpackChunkName: 'orderRefund' */ '../views/order/orderRefund'),
  },
  {
    path: '/incomeDetail',
    name: 'incomeDetail',
    component: () =>
      import(/* webpackChunkName: 'incomeDetail' */ '../views/user/incomeDetail'),
  },
  {
    path: '/incomeCash',
    name: 'incomeCash',
    component: () =>
      import(/* webpackChunkName: 'incomeCash' */ '../views/user/incomeCash'),
  },
]

const router = new VueRouter({
  routes,
})
router.beforeEach((to, from, next) => {
  if (to.name !== 'login' && !utils.storage.get('token')) {
  }
  next()
})

export default router
